package com.jiazhong.集合类.Collection.List.ArrayListDemo;

import java.util.ArrayList;

public class ArrayListDemo {
    public static void main(String[] args) {
        //创建ArrayList集合类对象
        ArrayList arrayList=new ArrayList();
        //向ArrayList的尾部追加元素
        arrayList.add("1");
        arrayList.add("3");
        arrayList.add(4);
        arrayList.add(5);
        arrayList.add(6);
        arrayList.add(7);
        System.out.println(arrayList);

        //向ArrayList的某个位置插入元素
        arrayList.add(2,"2");
        System.out.println(arrayList);

        //根据下标获得一个元素
        Object obj=arrayList.get(2);
        System.out.println(obj);
        //强转
        String str=(String) arrayList.get(2);
        System.out.println(str);

        ////移除元素
        arrayList.remove("2");
        System.out.println(arrayList);
        //根据下标移除
        arrayList.remove(0);
        System.out.println(arrayList);
        //如果参数为int类型，则根据下标移除,如果要移除的内容为整数则需要使用Integer类型删除
        arrayList.remove(new Integer(3));
        System.out.println(arrayList);

        arrayList.forEach(System.out::print);

        for (Object object:arrayList) {
            System.out.print(object);
        }

        for (int i=0;i<arrayList.size();i++){
            Object obj2=arrayList.get(i);
            System.out.print(obj2);
        }

    }
}
